#ifndef ABSTRACT_POLICY_H
#define ABSTRACT_POLICY_H

#include "../task/abstract_task.h"
#include <any>
#include <utility>

namespace policy
{
class AbstractPolicy;
using AbstractPolicyConstPtr = std::shared_ptr<AbstractPolicy>;
/**
 * @brief:  策略方式虚基类，其他策略继承此策略
 * @author: sherlock_lht
 */
class AbstractPolicy
{
public:
    explicit AbstractPolicy(const std::string &name)
        : name_(name)
    {}
    virtual ~AbstractPolicy() = default;

    void setTaskEventNotify(task::TaskEventNotify task_event_notify)
    {
        event_notify_ = std::move(task_event_notify);
    }

    void taskEventNotify(task::TaskEventType task_event_type)
    {
        if (event_notify_)
        {
            event_notify_(task_event_type);
        }
        else
        {
            EASE_WARN("policy: %s, event notify error, event type: %d", name_.c_str(), task_event_type);
        }
    }

    /**
     * @brief:  添加任务
     * @author: sherlock_lht
     */
    virtual bool addTask(const task::AbstractTaskConstPtr &task) = 0;

    virtual bool insertTask(int index, const task::AbstractTaskConstPtr &task) = 0;

    /**
     * @brief:  添加任务组
     * @author: sherlock_lht
     */
    virtual bool addPolicy(const AbstractPolicyConstPtr &policy) = 0;

    virtual bool insertPolicy(int index, const AbstractPolicyConstPtr &policy) = 0;

    /**
     * @brief:  设置任务
     * @author: sherlock_lht
     */
    virtual bool setTask(const task::AbstractTaskConstPtr &task) = 0;

    /**
     * @brief:  设置任务组
     * @author: sherlock_lht
     */
    virtual bool setPolicy(const AbstractPolicyConstPtr &policy) = 0;

    /**
     * @brief:  获取当前策略数据
     * @author: sherlock_lht
     */
    virtual std::any getPolicyData() = 0;

    /**
     * @brief:  设置上下文管理器
     * @author: sherlock_lht
     */
    virtual void setContext(task::Context *context) = 0;

    /**
     * @brief:  策略开始执行
     * @author: sherlock_lht
     */
    virtual void run() = 0;

    /**
     * @brief:  暂停策略执行
     * @author: sherlock_lht
     */
    virtual void pause() = 0;

    /**
     * @brief:  恢复策略执行
     * @author: sherlock_lht
     */
    virtual void resume() = 0;

    /**
     * @brief:  取消策略执行
     * @author: sherlock_lht
     */
    virtual void cancel() = 0;

    /**
     * @brief:  转字符串
     * @author: sherlock_lht
     */
    virtual std::string toString() const = 0;

protected:
    std::string name_;
    task::TaskEventNotify event_notify_;
};
}

#endif //ABSTRACT_POLICY_H
